package edu.fudan.cse.medlab.event.filter;

import java.io.File;

public class FileSize {
	public static long checkDirSize(String dirpath){
		try{
			File f = new File(dirpath);
			if(f.isFile())
				return FileSize.checkFileSize(dirpath);
			else{
				String[] s = f.list();
				long k = 0;
				if(s==null)
					return 0;
				for (int i = 0; i < s.length; i++) {
					k += FileSize.checkFileSize(dirpath+"\\"+s[i]);
				}
				return k;
			}
				
		}
		catch(Exception e){
			e.printStackTrace();
			return 0;
		}	
	}
	
	public static long checkFileSize(String filepath){
		try{
			File f = new File(filepath);
			return f.length();
		}
		catch(Exception e){
			e.printStackTrace();
			return 0;
		}
	}
	
	public static void main(String[] args){
		System.out.println(FileSize.checkFileSize("settings.txt"));
	}
}
